package test.enba.mq.producer.controller.activemq;

import com.enba.boot.mq.MqHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/activemq")
public class ActiveMqController {

  @Autowired private MqHelper mqHelper;

  /**
   * queue 发送消息
   *
   * @param destinationName
   * @param message
   * @return
   */
  @PostMapping("/queue/send-message")
  public ResponseEntity<String> sendMessageByQueue(
      @RequestParam String destinationName, @RequestParam String message) {

    return mqHelper.sendMessageByQueue(
        destinationName, message, () -> ResponseEntity.ok("发送队列消息成功"));
  }

  /**
   * topic 发送消息
   *
   * @param topic
   * @param message
   * @return
   */
  @PostMapping("/topic/send-message")
  public ResponseEntity<String> sendMessageByTopic(
      @RequestParam String topic, @RequestParam String message) {

    return mqHelper.sendMessageByTopic(topic, message, () -> ResponseEntity.ok("发送队列消息成功"));
  }

  /**
   * virtual topic 虚拟主题发送消息
   *
   * @param message
   * @return
   */
  @PostMapping("/virtual-topic/send-message")
  public ResponseEntity<String> sendMessageByTopicByGroup(@RequestParam String message) {

    return mqHelper.sendMessageByTopic(
        "VirtualTopic.myTopic", message, () -> ResponseEntity.ok("发送虚拟主题消息成功"));
  }
}
